package edu.cmu.arch.pipesandfilters;

import edu.cmu.arch.pipesandfilters.frame.Variable;

import java.io.File;
import java.io.IOException;
import java.util.*;

/**
* File:SystemC.java
* Course: 17655
* Project: Assignment 1
* Group: Group 1
* @author Michael Azzopardi
* Versions:
*	1.0 February 2012
*
* This is the main program for the implementation of the Pipe-and-Filter network for System C
* 
*/
public class CyclicFilterSystem {

	/**
	 * @param args
	 * @author Michael Azzopardi
	 * 
	 */
	public static void main(String[] args) {
		System.out.println("Initializing System C Pipe-and-Filter Network");
		System.out.println("developed by Group 1");
		System.out.println("=============================================");		
		try {
			// Define file names	
			String sourceFilenameA = "DataSets" + File.separator + "SubSetA.dat";
			String sourceFilenameB = "DataSets" + File.separator + "SubSetB.dat";
			String outputFilename = "DataSets" + File.separator + "OutputC.dat";
			String wildOutputFilenameA = "DataSets" + File.separator + "WildPointsA.dat";
			String wildOutputFilenameB = "DataSets" + File.separator + "WildPointsB.dat";
			
			
			// DefineFilters
			SourceFilter sourceFilterA;
	
			TimeSequentialMergeFilter mergeFilter;
	
			FileSinkFilter sinkFilter;

			ConversionFilter tempConversionFilter;
			
			ArrayList<Variable> stripMeasurements;				
			ArrayList<Variable> wildPointsMeasurementsA;
			ArrayList<Variable> wildPointsMeasurementsB;
			ArrayList<Variable> outputMeasurements;
			// Instantiate sourceFilter
			sourceFilterA = new SourceFilter();
			
			// Set fileName for sourceFilter
			sourceFilterA.setFileName(sourceFilenameA);
		
	
			// Instantiate filters
			stripMeasurements = new ArrayList<Variable>();
			stripMeasurements.add(Variable.Time);
			stripMeasurements.add(Variable.Temperature);
			stripMeasurements.add(Variable.Altitude);
			stripMeasurements.add(Variable.Pressure);
			stripMeasurements.add(Variable.Attitude);

			
			mergeFilter = new TimeSequentialMergeFilter();
			
			tempConversionFilter = new ConversionFilter(Variable.Temperature);
			
			// Initialize and set fileName, header and separator for sinkFilter
			outputMeasurements = new ArrayList<Variable>();
			outputMeasurements.add(Variable.Time);
			outputMeasurements.add(Variable.Temperature);
			outputMeasurements.add(Variable.Altitude);
			outputMeasurements.add(Variable.Pressure);			
			sinkFilter = new FileSinkFilter(outputMeasurements, outputFilename);
			
			// Connect filters

			tempConversionFilter.Connect(sourceFilterA);
			mergeFilter.Connect(tempConversionFilter,mergeFilter);
			//sinkFilter.Connect(mergeFilter);
			
			// Start filters
			/*
			
			tempConversionFilter.start();
			sourceFilterB.start();			
			stripFilterA.start();
			stripFilterB.start();
			mergeFilter.start();
			extrapolateFilter.start();
			rangeFilter.start();
			wildpointStripFilterA.start();
			wildpointStripFilterB.start();	
			outputStripFilter.start();
			sinkFilter.start();
			wildpointSinkFilterA.start();
			wildpointSinkFilterB.start();*/
			//sourceFilterA.start();
			sourceFilterA.start();
			tempConversionFilter.start();
			mergeFilter.start();
			//sinkFilter.start();
		} catch (IOException e) {
			System.out.println("Error : "+e.getMessage());
			e.printStackTrace();
		}			
	}

}

		
